home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / masm.zip / ASM4.DOC < prev    next >
Text File  |  1993-04-07  |  5KB  |  133 lines

  1.  
  2.  
  3. ;COLORINIT EQU       03H       ;Value to initialize color screen (80x25)
  4. COLORINIT EQU      01H       ;Value to initialize color screen (40X25)
  5. ;
  6. ;         Now, describe our own segment
  7. ;
  8. SETSCRN   SEGMENT             ;Set operating segment for CODE and DATA
  9. ;
  10.           ASSUME CS:SETSCRN,DS:SETSCRN,ES:SETSCRN,SS:SETSCRN    ;All segments
  11. ;
  12.           ORG       100H      ;Begin assembly at standard .COM offset
  13. ;
  14. MAIN      PROC      NEAR      ;COM files use NEAR linkage
  15.           JMP       BEGIN     ;And, it is helpful to put the data first, but
  16. ;                             ;then you must branch around it.
  17. ;
  18. ;         Data used in SETSCRN
  19. ;
  20. CHANGELOC   DD      EQUIP     ;Location of the EQUIP, recorded as far pointer
  21. MONOPROMPT  DB      'Please press the plus ( + ) key.$'    ;User sees on mono
  22. COLORPROMPT DB      'Please press the minus ( - ) key.$'   ;User sees on color
  23.  
  24.  
  25. Several things are illustrated on this page.  First, in addition to titles,
  26. the assembler supports subtitles:  hence the SUBTTL pseudo-op.  Second, the
  27. PAGE pseudo-op can be used to go to a new page in the listing.  You see an
  28. example here of the DSECT-style segment in the "SEGMENT AT 40H".  Here, our
  29. our interest is in correctly describing the location of some data in the
  30. BIOS work area which really is located at segment 40H.
  31.  
  32. You will also see illustrated the EQU instruction, which just gives a sym-
  33. bolic name to a number.  I don't make a fetish of giving a name to every
  34. single number in a program.  I do feel strongly, though, that interrupts
  35. and function codes, where the number is arbitrary and the function being
  36. performed is the thing of interest, should always be given symbolic names.
  37.  
  38. One last new element in this section is the define doubleword (DD) instruc-
  39. tion.  A doubleword constant can refer, as in this case, to a location in
  40. another segment.  The assembler will be happy to use information at its
  41. disposal to properly assemble it.  In this case, the assembler knows that
  42. EQUIP is offset 10 in the segment BIOSDATA which is at 40H.
  43.  
  44.           SUBTTL -- Perform function
  45.           PAGE
  46. BEGIN:    CALL      MONOON                  ;Turn on mono display
  47.           MOV       DX,OFFSET MONOPROMPT          ;GET MONO PROMPT
  48.           MOV       AH,PRTMSG                     ;ISSUE
  49.           INT       DOS                           ;IT
  50.           CALL      COLORON                 ;Turn on color display
  51.           MOV       DX,OFFSET COLORPROMPT         ;GET COLOR PROMPT
  52.           MOV       AH,PRTMSG                     ;ISSUE
  53.           INT       DOS                           ;IT
  54.           MOV       AH,GETKEY               ;Obtain user response
  55.           INT       KBD
  56.           CMP       AL,'+'                  ;Does he want MONO?
  57.           JNZ       NOMONO
  58.  
  59.  
  60. IBM PC Assembly Language Tutorial                                        26
  61.  
  62.  
  63.           CALL      MONOON                  ;yes.  give it to him
  64. NOMONO:   RET
  65. MAIN      ENDP
  66.  
  67.  
  68. The main code section makes use of subroutines to keep the basic flow sim-
  69. ple.  About all that's new to you in this section is the use of the BIOS
  70. interrupt KBD to read a character from the keyboard.
  71.  
  72. Now for the subroutines, MONOON and COLORON:
  73.  
  74.           SUBTTL -- Routines to turn monitors on
  75.           PAGE
  76. MONOON    PROC      NEAR                ;Turn mono on
  77.           LES       DI,CHANGELOC        ;Get location to change
  78.           ASSUME    ES:BIOSDATA         ;TELL ASSEMBLER ABOUT CHANGE TO ES
  79.           OR        EQUIP,MONO
  80.           MOV       AX,MONOINIT         ;Get screen initialization value
  81.           INT       SCREEN              ;Initialize screen
  82.           RET
  83. MONOON    ENDP
  84. COLORON   PROC      NEAR                ;Turn color on
  85.           LES       DI,CHANGELOC        ;Get location to change
  86.           ASSUME    ES:BIOSDATA         ;TELL ASSEMBLER ABOUT CHANGE TO ES
  87.           AND       EQUIP,COLOR
  88.           MOV       AX,COLORINIT        ;Get screen initialization value
  89.           INT       SCREEN              ;Initialize screen
  90.           RET
  91. COLORON   ENDP
  92. SETSCRN   ENDS                          ;End of segment
  93.           END       MAIN                ;End of assembly; execution at MAIN
  94.  
  95.  
  96. The instructions LES and LDS are useful ones for dealing with doubleword
  97. addresses.  The offset is loaded into the operand register and the segment
  98. into ES (for LES) or DS (for LDS).  By telling the assembler, with an
  99. ASSUME, that ES now addresses the BIOSDATA segment, it is able to correctly
  100. assemble the OR and AND instructions which refer to the EQUIP byte.  An ES
  101. segment prefix is added.
  102.  
  103. To understand the action here, you simply need to know that flags in that
  104. particular byte control how the BIOS screen service initializes the adapt-
  105. ers.  BIOS will only work with one adapter at a time; by setting the equip-
  106. ment flags to show one or the other as installed and calling BIOS screen
  107. initialization, we achieve the desired effect.
  108.  
  109. The rest is up to you.
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. IBM PC Assembly Language Tutorial                                        27.
  121.  
  122. The rest is up to you.
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133. IBM PC Assembly Language Tutorial                                        27